package com.war.dao.safeManage;

import com.war.pojo.system.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserDao {
    //手机号登录
    @Select("select * from sys_user where tel=#{tel} and login_pwd=#{login_pwd}")
    User login(User user);

    //查询用户的邮箱
    @Select("select * from sys_user where email=#{email}")
    List<User> valEmail(User user);

    //查询用户的盐值
    @Select("select salt from sys_user where tel=#{tel}")
    String valSalt(User user);

    //查用户名
    @Select("select * from sys_user where id=#{id}")
    User selectNameById(User user);

    //查询所有用户
    @Select("select * from sys_user ")
    List<User> selectAll();

    //根据身份查询
    @Select("select * from sys_user where identity=#{identity}")
    List<User> findByUserId(User user);

    //根据姓名查询
    @Select("select * from sys_user where name=#{name}")
    List<User> findByUserName(User user);

    //修改用户信息
    @Update("update sys_user set name=#{name}, identity=#{identity}, sex=#{sex}, tel=#{tel}, email=#{email}, login_pwd=#{login_pwd}, salt=#{salt} where tel=#{oldTel}")
    int updateUser(User user);

    //修改身份
    @Update("update sys_user set identity=#{identity} where tel=#{tel}")
    int updateIdentity(User user);

    //删除
    @Delete("delete from sys_user where tel=#{tel}")
    int delUser(User user);

    //根据手机号查询
    @Select("select * from sys_user where tel=#{tel}")
    User findByTel(User user);

    //注册用户
    @Insert("insert into sys_user(name, identity, sex, tel, email, login_pwd, salt) value(#{name}, #{identity}, #{sex}, #{tel}, #{email}, #{login_pwd}, #{salt})")
    int register(User user);
}
